package org.misalen.web.database.model.mysql.sys;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.misalen.annotations.ModelComment;
import org.misalen.web.database.model.mysql.BaseSqlModel;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * 资源表
 * 
 * @author guochao
 *
 */
@Entity
@Table(name = "SysResources")
@DynamicInsert(true)
@DynamicUpdate(true)
@JsonIgnoreProperties(value = { "sysRoleResources" })
public class SysResources extends BaseSqlModel {

	@ModelComment("资源名称")
	@Column(name = "resourceName", length = 50, nullable = false)
	private String resourceName;

	@ModelComment("自关联id")
	@Column(name = "parentId")
	private String parentId;

	@ModelComment("图标")
	@Column(name = "icon", length = 50)
	private String icon;

	@ModelComment("排序字段")
	@Column(name = "seq", length = 10, nullable = false)
	private Integer seq;

	@ModelComment("资源地址")
	@Column(name = "resourceUrl")
	private String resourceUrl;

	@ModelComment("保存类型")
	@Column(name = "saveType", length = 20, nullable = false)
	private String saveType;

	@ModelComment("状态(available 可用)")
	@Column(name = "usingState")
	private String usingState;

	@ModelComment("角色资源关系")
	@OneToMany(targetEntity = SysRoleResources.class, cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(name = "resourcesId", updatable = false)
	private Set<SysRoleResources> sysRoleResources;

	@Transient
	private Set<SysResources> children;

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public Set<SysResources> getChildren() {
		return children;
	}

	public void setChildren(Set<SysResources> children) {
		this.children = children;
	}

	public Set<SysRoleResources> getSysRoleResources() {
		return sysRoleResources;
	}

	public void setSysRoleResources(Set<SysRoleResources> sysRoleResources) {
		this.sysRoleResources = sysRoleResources;
	}

	public String getResourceName() {
		return resourceName;
	}

	public void setResourceName(String resourceName) {
		this.resourceName = resourceName;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public Integer getSeq() {
		return seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	public String getResourceUrl() {
		return resourceUrl;
	}

	public void setResourceUrl(String resourceUrl) {
		this.resourceUrl = resourceUrl;
	}

	public String getSaveType() {
		return saveType;
	}

	public void setSaveType(String saveType) {
		this.saveType = saveType;
	}

	public String getUsingState() {
		return usingState;
	}

	public void setUsingState(String usingState) {
		this.usingState = usingState;
	}

	public static enum SaveType {
		menu1, menu2, button
	}
}
